package com.tarena.verification.orNull;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

import org.springframework.util.StringUtils;

import com.tarena.verification.CustomerValidInterface;
import com.tarena.verification.exception.VerificationException;
/**
 * notNull 方法类
 * @author lsc
 *
 */
public class NotNullMethod implements CustomerValidInterface{
	private NotNull notNull ;
	
	/**
	 * 
	 * @param annotation
	 * @param obj       标注到字段上  字段的值
	 * @return
	 * @throws VerificationException
	 */
	@Override
	public boolean valid(Annotation annotation,Object obj,String organize) throws VerificationException {
		System.out.println("not null 验证");
		   this.notNull = (NotNull) annotation;
		   String annoOrg = notNull.organize();
		   if(!StringUtils.isEmpty(organize)) {
			   if(organize.equals(annoOrg)) {
				   if (obj==null || obj == ""  || StringUtils.isEmpty(obj) || "''".equals(obj) ) {
		                  System.err.println(notNull.msg());
		                  throw new VerificationException(notNull.msg());
		           }
			   }
		   }else {
			   if (obj==null || obj == ""  || StringUtils.isEmpty(obj) || "''".equals(obj) ) {
	                  System.err.println(notNull.msg());
	                  throw new VerificationException(notNull.msg());
	           }
		   }
		return true;
	}

	public NotNull getNotNull() {
		return notNull;
	}

	public void setNotNull(NotNull notNull) {
		this.notNull = notNull;
	}

	
}
